﻿Public Class Frm_Rech_Massarif_khibra

    Private Sub Frm_Rech_Massarif_khibra_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Massarif_khibra.Enabled = True
    End Sub

    Private Sub Frm_Rech_Massarif_khibra_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
        txt_marji3ona.Text = Frm_Massarif_khibra.dv.Num
        txt_num_khibr.Text = Frm_Massarif_khibra.comb_num_khibra.Text

    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "رقم الوصل" Then

                For Each av As Depenses_khibra In Frm_Massarif_khibra.avo.List_depences_khibra
                    If av.Num_recus.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num_recus, av.Num_compt, av.Date_depence}))

                    End If

                Next


            ElseIf comb_matorido_elbaht.SelectedItem = "رقم الحساب" Then

                For Each av As Depenses_khibra In Frm_Massarif_khibra.avo.List_depences_khibra
                    If av.Num_compt.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num_recus, av.Num_compt, av.Date_depence}))

                    End If

                Next

            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click

        If List_tous.SelectedIndices.Count > 0 Then
            Dim j As Integer = 0
            Dim avova As Depenses_khibra
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    avova = Partager.list_recherch.Item(i)
                    For Each khib As Depenses_khibra In Frm_Massarif_khibra.avo.List_depences_khibra
                        If avova.Id = khib.Id Then
                            Frm_Massarif_khibra.List_tous.Items(j).Focused = True
                            Frm_Massarif_khibra.List_tous.Items(j).Selected = True
                        End If
                        j += 1
                    Next
                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر مصاريف من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub

    Private Sub comb_matorido_elbaht_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comb_matorido_elbaht.SelectedIndexChanged
        txt_rech.Clear()
    End Sub
End Class